/**
 * 快速定位搜索接口
 * 登录：identityInfo
 * 注册：register
 * 个人信息：myInfo
 * 七牛云token：getQiNiuToken
 * 获取省市区：areas
 * 搜索地址：searchAddress
 * 获取门牌号：rooms
 * 添加身份：addIdentity
 * 审核列表：auditList
 * 缴费列表：ServerUser
 * 缴费服务：buyServices
 * 发布出租信息：sendRent
 **/
import api from '../index.js';

var user = {};

// 微信登录
user.identityInfo = function(page, limit) {
	return new Promise((resolve, reject) => {
		api.get(api.url.MyHouseholds, {
				page: page,
				limit: limit
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 注册
user.register = function(data) {
	return new Promise((resolve, reject) => {
		api.post(api.url.UserInfo, data,
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 获取个人信息
user.myInfo = function() {
	return new Promise((resolve, reject) => {
		api.get(api.url.UserInfo, {},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 获取七牛云token
user.getQiNiuToken = function() {
	return new Promise((resolve, reject) => {
		api.get(api.url.QiNiuToken, {},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 获取省市区。。
user.areas = function(page, limit, parent_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Areas, {
				page: page,
				limit: limit,
				parent_id: parent_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 搜索地址
user.searchAddress = function(page, limit, area_id, address) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Addresses, {
				page: page,
				limit: limit,
				area_id: area_id,
				address: address
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 获取门牌号
user.rooms = function(page, limit, address_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Rooms, {
				page: page,
				limit: limit,
				address_id: address_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 添加身份
user.addIdentity = function(data) {
	return new Promise((resolve, reject) => {
		api.post(api.url.Household, data,
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 添加家庭成员
user.addFamilyMenber = function(data) {
	return new Promise((resolve, reject) => {
		api.post(api.url.Child, data,
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}


// 获取审核列表
/**
 * type1 1 获取户主可以审核的列表，4 物业可以审核的列表
 * type2 2租客 3家庭成员 4物业
 * state 0全部 1待审核 2已通过 3未通过
 **/
user.auditList = function(page, limit, address_id, type1, type2, name, state) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Households, {
				page: page,
				limit: limit,
				address_id: address_id,
				type1: type1,
				type2: type2,
				name: name,
				state: state
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 缴费列表
user.payCost = function(page, limit, address_id, name) {
	return new Promise((resolve, reject) => {
		api.get(api.url.ServerUser, {
				page: page,
				limit: limit,
				address_id: address_id,
				name: name
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 授权列表
user.authList = function(page, limit, address_id, name) {
	return new Promise((resolve, reject) => {
		api.get(api.url.AuthList, {
				page: page,
				limit: limit,
				address_id: address_id,
				name: name
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 缴费服务
user.buyServices = function(page, limit) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Buys, {
				page: page,
				limit: limit
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 缴费账单
user.billList = function(page, limit, user_id, face_id) {
	return new Promise((resolve, reject) => {
		api.get(api.url.Orders, {
				page: page,
				limit: limit,
				user_id: user_id,
				face_id: face_id
			},
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

// 发布出租信息
user.sendRent = function(data) {
	return new Promise((resolve, reject) => {
		api.post(api.url.CreationMessageIssues, data,
			(response) => {
				if (response.msg = "ok") {
					var res = response;
					resolve(res);
				} else {
					reject(response);
				}
			})
	})
}

module.exports = user;
